#
# NESDROID
# 
# SEE LICENSE FILE FOR LICENSE INFO
# 
# Copyright 2011 Stephen Damm (Halsafar)
# All rights reserved.
# shinhalsafar@gmail.com
#

# OPTIONS
ENABLE_BLUETOOTH 		:= 0
ENABLE_DEBUG 			:= 0
ENABLE_DEBUG_LOGGING 	:= 1
ENABLE_LUA				:= 0


# STORE VARS FOR AFTER CLEANING
LOCAL_PATH := $(call my-dir)
ORG_PATH := $(LOCAL_PATH)


# BUILD ALL EXTERNAL LIBS
include $(CLEAR_VARS)
include $(call all-makefiles-under,$(LOCAL_PATH))


# BUILD EMU LIB
include $(CLEAR_VARS)
LOCAL_PATH := $(ORG_PATH)/
LOCAL_MODULE_TAGS := user
LOCAL_ARM_MODE := arm
LOCAL_MODULE := libemu

LIB_EMU_DIR := libemu

MY_FILES 	:=	\
				$(wildcard $(LOCAL_PATH)/../fceu_src/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/mappers/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/mappers/*.c) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/boards/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/input/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/utils/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/drivers/common/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/drivers/common/*.c)

ifeq ($(ENABLE_LUA), 1)
MY_FILES	+=	\
				$(wildcard $(LOCAL_PATH)/../fceu_src/lua/src/*.c) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/*.c)	
endif 				

		
# Correct the file names		
MY_FILES := $(MY_FILES:$(LOCAL_PATH)/%=%) 


# Emulator Engine source files that we will compile.
LOCAL_SRC_FILES := \
	$(MY_FILES) \
	$(LIB_EMU_DIR)/rewind.c \
	$(LIB_EMU_DIR)/GraphicsDriver.cpp \
	$(LIB_EMU_DIR)/InputHandler.cpp \
	$(LIB_EMU_DIR)/Quad.cpp \
	FceuSystem.cpp \
	EmulatorBridge.cpp \
	Application.cpp
	
ifeq ($(ENABLE_BLUETOOTH), 1)
	LOCAL_SRC_FILES += $(LIB_EMU_DIR)/bluetooth/BluetoothFacade.cpp
endif
		
		
# INCLUDE DIRS
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../ \
					$(LOCAL_PATH)/libemu/ \
					$(LOCAL_PATH)/libemu/bluetooth/inc/android \
					$(LOCAL_PATH)/../fceu_src/lua/src/		
	   
	                  
# Debug
LOCAL_CFLAGS := -DLOG_TAG=\"NESDroidNative\"
ifeq ($(ENABLE_DEBUG), 1)
	# DEBUG FLAGS
	LOCAL_CFLAGS += -g
else
	# RELEASE/Optimization flags
	LOCAL_CFLAGS += -O3 \
					-ffast-math \
					-fomit-frame-pointer \
					-fvisibility=hidden \
					-funit-at-a-time
					#-finline-functions
					#-funroll-loops \
					#-finline-functions \
					#-mfloat-abi=softfp \
					#-mfpu=neon
					#--param inline-unit-growth=1000 \
					#--param large-function-growth=5000 \
					#--param max-inline-insns-single=2450
					# -fvisibility=hidden
endif

ifeq ($(ENABLE_DEBUG_LOGGING), 1)
	LOCAL_CFLAGS += -DDEBUG_LOGGING
endif
				
			
# Compiler Remove Warning flags
#LOCAL_CFLAGS += -Winline
LOCAL_CFLAGS += -Wno-write-strings


# Halsafars custom flag, TODO - remove these they are used for poc changes
LOCAL_CFLAGS += -DHALDROID


# ANDROID STL FLAGS
LOCAL_CFLAGS += -D_STLP_HAS_WCHAR_T -D_GLIBCXX_USE_WCHAR_T


# FCEU Flags
LOCAL_CFLAGS += -DPSS_STYLE=1 -DHAVE_ASPRINTF -DC80x86 -DLSB_FIRST -DFRAMESKIP


# FCEU Enable Lua
ifeq ($(ENABLE_LUA), 1) 
	LOCAL_CFLAGS += -D_S9XLUA_H -D_USE_FCEU_LUA_ENGINE
endif


# Copy C Flags to CXX flags
#LOCAL_CPPFLAGS := $(LOCAL_CFLAGS)
#LOCAL_CXXFLAGS := $(LOCAL_CFLAGS)
     
     
# C99
LOCAL_CFLAGS += -std=c99     


# Native libs to link to
LOCAL_LDLIBS := -lz -llog -lGLESv2


# All of the shared libraries we link against.
LOCAL_SHARED_LIBRARIES := libzip libgnupng

                   
# Static libraries.              
LOCAL_STATIC_LIBRARIES :=   


# Don't prelink this library.  For more efficient code, you may want
# to add this library to the prelink map and set this to true. However,
# it's difficult to do this for applications that are not supplied as
# part of a system image.
LOCAL_PRELINK_MODULE := false

include $(BUILD_SHARED_LIBRARY)


